﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GameBoardViewer.Common
{
    public class GameBoardCheckButton: GameBoardButton
    {
        protected Texture2D _clrChecked;
        protected Texture2D _clrHoverChecked;

        public GameBoardCheckButton(Game game, IMainBoard mainBoard)
            : base(game, mainBoard)
        {
            IsChecked = false;
            this.ButtonPressed += new EventHandler(GameBoardCheckButton_ButtonPressed);
        }

        public bool IsChecked
        { get; set; }

        public void LoadContent(string sTexture, int marginX, int marginY, enumButtonDockStyle dockStyle, 
                    Color clrHover, Color clrPressed, Color clrChecked, Color clrHoverChecked)
        {
            base.LoadContent(sTexture, marginX, marginY, dockStyle, clrHover, clrPressed);

            Color[] data = new Color[1];
            _clrChecked = new Texture2D(_game.GraphicsDevice, 1, 1);
            _clrChecked.GetData<Color>(data);
            data[0] = clrChecked;
            _clrChecked.SetData<Color>(data);

            data = new Color[1];
            _clrHoverChecked = new Texture2D(_game.GraphicsDevice, 1, 1);
            _clrHoverChecked.GetData<Color>(data);
            data[0] = clrHoverChecked;
            _clrHoverChecked.SetData<Color>(data);
        }

        public override void Draw()
        {
            if (IsChecked == true)
            {
                Rectangle rect = GetButtonRect();

                DrawPicture();

                _batch.Begin();

                if (_isHover == true)
                {
                    _batch.Draw(_clrHoverChecked, rect, Color.White);
                }
                else
                {
                    _batch.Draw(_clrChecked, rect, Color.White);
                }

                _batch.End();
            }
            else
            {
                base.Draw();
            }
        }

        void GameBoardCheckButton_ButtonPressed(object sender, EventArgs e)
        {
            IsChecked = !IsChecked;
        }
        
    }
}
